/**
 *Classe responsavel pela visao isometrica do game
 */
 
import corejuliano.designpattern.mvc.*;
import flash.geom.*;
import corejuliano.gameelement.*;
 
class corejuliano.gameelement.perspective.IsometricView extends View 
{
	public function IsometricView(canvas:MovieClip, model:Model)
	{
		super(canvas, model);
	}
	
	public function createMoviClip(canvas:MovieClip):Void
	{
		var id:String = model.getId();
		id += "_isometric";
		graphic = canvas.attachMovie(id,id + canvas.getNextHighestDepth(),calculateDepth());
	}
	
	public function updateScreen():Void
	{
		var position = calculateIsometricPosition();
		graphic._x = position.x;
		graphic._y = position.y;
		graphic.swapDepths(calculateDepth());
	}
	
	public function calculateDepth():Number
	{
		var tile:Tile = TileableModel(model).getTile();
		return tile.getDepth() + TileableModel(model).getZIndex(); 
	}
	
	public function calculateIsometricPosition():Point
	{
		var position:Point = new Point();
		position.x = ( model.getPosition().x + model.getPosition().y) / 2;		
		position.y = ((( model.getPosition().x + model.getPosition().y) / 2) - model.getPosition().x) /2;
		
		return position;	
	}
	
	public function destroy():Void
	{
		graphic = null;		
		super.destroy();
	}
}